<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>MVEL</title><link rel="stylesheet" type="text/css" href="eclipse_book.css"><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"><link rel="home" href="index.html" title="Red Hat Fuse Tooling"><link rel="up" href="RiderExLang.html" title="Part&nbsp;III.&nbsp;Expression and Predicates Languages"><link rel="prev" href="JXPath.html" title="JXPath"><link rel="next" href="OGNL.html" title="The Object-Graph Navigation Language(OGNL)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="MVEL"></a>MVEL</h2></div></div></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33205"></a>Overview</h2></div></div></div><p><a class="link" href="http://johannburkard.de/blog/programming/java/mvel-templating-introduction.html" target="_top">MVEL</a> is a Java-based dynamic language
that is similar to OGNL, but is reported to be much faster. The MVEL support is in the
<code class="literal">camel-mvel</code> module.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33206"></a>Syntax</h2></div></div></div><p>You use the MVEL dot syntax to invoke Java methods, for example:</p><pre class="screen">getRequest().getBody().getFamilyName()</pre><p>Because MVEL is dynamically typed, it is unnecessary to cast the message body instance (of
<code class="literal">Object</code> type) before invoking the <code class="literal">getFamilyName()</code> method. You can
also use an abbreviated syntax for invoking bean attributes, for example:</p><pre class="screen">request.body.familyName</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33207"></a>Adding the MVEL module</h2></div></div></div><p>To use MVEL in your routes you need to add a dependency on
<code class="literal">camel-mvel</code> to your project as shown in
<a class="xref" href="MVEL.html#ExPredLangMVELEx060" title="Example&nbsp;9.&nbsp;Adding the camel-mvel dependency">Example&nbsp;9, &#8220;Adding the camel-mvel dependency&#8221;</a>.</p><div class="example"><a name="ExPredLangMVELEx060"></a><p class="title"><b>Example&nbsp;9.&nbsp;Adding the camel-mvel dependency</b></p><div class="example-contents"><pre class="screen">&lt;!-- Maven POM File --&gt;
&lt;properties&gt;
  &lt;camel-version&gt;2.21.0.fuse-730078-redhat-00001&lt;/camel-version&gt;
  ...
&lt;/properties&gt;

&lt;dependencies&gt;
  ...
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-mvel&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
  &lt;/dependency&gt;
  ...
&lt;/dependencies&gt;</pre></div></div><br class="example-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33208"></a>Built-in variables</h2></div></div></div><p><a class="xref" href="MVEL.html#MVELAttTbl010" title="Table&nbsp;11.&nbsp;MVEL variables">Table&nbsp;11, &#8220;MVEL variables&#8221;</a> lists the built-in variables that are accessible
when using MVEL.</p><div class="table"><a name="MVELAttTbl010"></a><p class="title"><b>Table&nbsp;11.&nbsp;MVEL variables</b></p><div class="table-contents"><table summary="MVEL variables" border="1"><colgroup><col width="33%" class="col_1"><col width="33%" class="col_2"><col width="34%" class="col_3"></colgroup><thead><tr><th align="left" valign="top">Name</th><th align="left" valign="top">Type</th><th align="left" valign="top">Description</th></tr></thead><tbody><tr><td align="left" valign="top"><p><code class="literal">this</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exchange</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exception</code></p></td><td align="left" valign="top"><p><code class="literal">Throwable</code></p></td><td align="left" valign="top"><p>the Exchange exception (if any)</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">exchangeID</code></p></td><td align="left" valign="top"><p><code class="literal">String</code></p></td><td align="left" valign="top"><p>the Exchange ID</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">fault</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The Fault message(if any)</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">request</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The IN message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">response</code></p></td><td align="left" valign="top"><p><code class="literal">org.apache.camel.Message</code></p></td><td align="left" valign="top"><p>The OUT message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">properties</code></p></td><td align="left" valign="top"><p><code class="literal">Map</code></p></td><td align="left" valign="top"><p>The Exchange properties</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">property(<span class="emphasis"><em>name</em></span>)</code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The value of the named Exchange property</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">property(<span class="emphasis"><em>name</em></span>, <span class="emphasis"><em>type</em></span>)</code></p></td><td align="left" valign="top"><p><code class="literal"><span class="emphasis"><em>Type</em></span></code></p></td><td align="left" valign="top"><p>The typed value of the named Exchange property</p></td></tr></tbody></table></div></div><br class="table-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33209"></a>Example</h2></div></div></div><p><a class="xref" href="MVEL.html#ExPredLangMVELEx090" title="Example&nbsp;10.&nbsp;Route using MVEL">Example&nbsp;10, &#8220;Route using MVEL&#8221;</a> shows a route that uses MVEL.</p><div class="example"><a name="ExPredLangMVELEx090"></a><p class="title"><b>Example&nbsp;10.&nbsp;Route using MVEL</b></p><div class="example-contents"><pre class="screen">&lt;camelContext&gt;
  &lt;route&gt;
    &lt;from uri="seda:foo"/&gt;
    &lt;filter&gt;
      &lt;language langauge="mvel"&gt;request.headers.foo == 'bar'&lt;/language&gt;
      &lt;to uri="seda:bar"/&gt;
    &lt;/filter&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;</pre></div></div><br class="example-break"></div></div></body></html>